package com.ls.fw.index.solr.client.service.base.impl;

import java.io.Serializable;
import java.util.List;

import org.apache.commons.collections.IteratorUtils;
import org.springframework.transaction.annotation.Transactional;

import com.ls.fw.index.solr.client.dao.base.BaseSolrGenericDao;
import com.ls.fw.index.solr.client.service.base.BaseSolrService;

public abstract class BaseSolrServiceImpl<T, PK extends Serializable>implements BaseSolrService<T, PK>  {

	protected abstract <E extends BaseSolrGenericDao<T, PK>> E getDao();
	
	@SuppressWarnings("unchecked")
	public List<T> findAll(){
		return IteratorUtils.toList(this.getDao().getBaseSolrDao().findAll().iterator());
	}

	@Transactional
	public void delete(PK id){
		this.getDao().getBaseSolrDao().delete(id);
	}

	@Transactional
	public void delete(T model){
		this.getDao().getBaseSolrDao().delete(model);
	}
	
	@Transactional
	public T save(T model){
		return this.getDao().getBaseSolrDao().save(model);
	}
	
	@Transactional
	public T update(T model){
		return this.getDao().getBaseSolrDao().save(model);
	}
	
	public T find(PK id){
		return this.getDao().getBaseSolrDao().findOne(id);
	}
}
